//箭头函数
var a=x=>x*x;
console.log('你的版本可以玩');

x=>{
    if (x>0) {
        return x*x;
    }
    else{
        return -x*x;
    }
};

console.log();
//
(x,y,...rest)=>{
    var i,sum=x+y;
    for (let index = 0; index < rest.length; index++) {
        sum=sum+rest[index];
        
    }
    return sum;
}

function add(x,y,...rset) {
  
    console.log(x);
    console.log(y);
    console.log(rset);
}
add();
add(1,2);
add(1,2,7,9,8,10);


let abd=(x,y,...rset)=>{
  
    console.log(x);
    console.log(y);
    console.log(rset);
}
abd(4);
//无参
()=>3.14

let tt=(x)=>{
    name:'迪迦'
}
console.log(tt());

let tt1=(x)=>({
    name:'迪迦'
})
console.log(tt1());

let tt2=(x)=>{return{
    name:'迪迦'
}}
console.log(tt2());

var obj={
    birth:1990,
    getage:function () {
        var b=this.birth;
        var fn=function () {
            return new Date().getFullYear()-this.birth;
        }
    }
};
console.log(obj.getage());

//无参的
var aat={
    bith:2000,
   getage:function () {
       var s=this.bith;
       var fn =()=>new Date().getFullYear()-this.bith
       return fn();
   }
}
console.log(aat.getage());

var aat1={
    bith:1990,
   getage:function (year) {
       var s=this.bith;
       var fn =(y)=>y -this.bith
       return fn.call({bith:1990},year);
   }
}
console.log(aat1.getage(1992));


var arr =[10,20,1,2];
arr.sort((x,y)=>x-y
    
);
console.log(arr);

//匿名函数
let aaat=(function (x) {
    return x*x;
})(3);

console.log(aaat);

